package ProOF.apl.problems.real.operators;

import ProOF.apl.problems.real.RealCodification;
import ProOF.apl.problems.real.RealProblem;
import ProOF.com.LinkerParameters;
import ProOF.gen.operator.oMutation;

public class RealMutSwap extends oMutation<RealProblem, RealCodification> {    
    @Override
    public String name() {
        return "Swap";
    }

    @Override
    public void parameters(LinkerParameters win) throws Exception {}
    
    @Override
    public void mutation(RealProblem prob, RealCodification ind) throws Exception {
    	int    posA;
    	int    posB;
    	double tmp;
    	if(prob.func.dimension() > 1){
    		posB = posA = prob.rmd.nextInt(prob.func.dimension());
    		while(posA == posB){
    			posB = prob.rmd.nextInt(prob.func.dimension());
    		}
    		tmp  = ind.x[posA];
    		ind.x[posA] = ind.x[posB];
    		ind.x[posB] = tmp;
    		prob.func.adjust(ind.x);
    	}
    }
}
